require("../../public/css/common.css")
require("../../public/css/normalize.css")
require("../../libs/fonts/iconfont.css")
require("./index.css")

// 引入axios
const axios = require("axios")
// 引入轮播图
require("../../public/swiper/swiper-bundle.min.css")
const Swiper = require("../../public/swiper/swiper-bundle.min.js")
// 引入轮播图js
var mySwiper = new Swiper('.swiper', {
  loop: true, // 循环模式选项
  autoplay: true,
  // 如果需要分页器
  pagination: {
    el: '.swiper-pagination',
  },
})

//   完成打卡操作
let btn = document.querySelector(".content-right .btn")
btn.addEventListener("click", function () {
  // 点击按钮之后,请求后台数据
  axios.post("http://47.96.154.185:3701/api/user/clockIn", {}, {
    headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
  })
    .then(function (re) {
      // console.log(re.data);
      if (re.data.errno === 0) {
        btn.disabled = true
        btn.innerHTML = "已打卡"
      } else {

        btn.innerHTML = re.data.message;
      }
    })
  //  判断用户今天是否已经打卡
  axios.get("http://47.96.154.185:3701/api/user/clockInInfo", {
    headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
  })
    .then(function (re) {
      console.log(re.data.data)
      if (re.data.data.isClockIn) {
        btn.disabled = true
        btn.innerHTML = "已打卡"
      }
    })

})
// 获取累计打开天数
axios.get("http://47.96.154.185:3701/api/user/info", {
  headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
})
  .then(function (re) {
    if (re.data.data["member.clockCount"]) {

      document.querySelector(".content-right .sum").innerHTML = `累计打卡${re.data.data["member.clockCount"]}天`
    } else {
      document.querySelector(".content-right .sum").innerHTML = `累计打卡0天`
    }
  })
// 获取今日排名
axios.get("http://47.96.154.185:3701/api/user/info", {
  headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
}).then(function (re) {
  document.querySelector(".QW").innerHTML=re.data.data.ranking
  
})
// 累计运动徽章
axios.
get("http://47.96.154.185:3701/api/user/info", {
  headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
}).then(function(re){
  document.querySelector(".num").innerHTML=re.data.data.badges
})
// 给底部按钮加颜色
let qq=document.querySelectorAll(".qq")
let index=0
qq.forEach(function(v,i){
  qq[0].style.color="blue"
  v.addEventListener("click",function(){
    qq[index].style.color="#000"
    v.style.color="blue"
    index=i
  })
})

